/* 
 * File:   IStorage.h
 * Author: alexey
 *
 * Created on 30 Март 2011 г., 19:29
 */

#ifndef ISTORAGE_H
#define	ISTORAGE_H

#include <sys/types.h>
#include <IDirectory.h>
#include <IServiceLocator.h>
#include <vector>
#include <map>
#include <string>
#include "../md5/md5.h"

namespace storagemon
{
    class IStorage: public IService
    {
    public:
        virtual ~IStorage() {};
        virtual bool operator==(const IStorage &other) const
        {
            bool res = true;
            if (other.id() != this->id())
                res = false;
            if (strcmp(other.name(), this->name()) != 0)
                res = false;
            if (strcmp(other.path(), this->path()) != 0)
                res = false;
            return res;
        }
    public:
        virtual u_long id() const = 0;
        virtual const char* name() const = 0;
        virtual const char* path() const = 0;
        virtual bool add_dir(IDirectory* dir) = 0;
        virtual bool remove_dir(u_long id) = 0;
        virtual u_long size() const = 0;
        virtual std::vector<IDirectory*>::iterator get_dir(u_long id) = 0;
    };

    class IStorageServiceFactory: public IService
    {
    public:
        typedef IService* (*CreateStorageServiceCallback)(const char* name,
                const char* path, u_long id, u_long parent_id,
                char md5[MD5_DIGEST_SIZE]);
    protected:
        typedef std::map<std::string, CreateStorageServiceCallback> CallbackMap;
    public:
        virtual ~IStorageServiceFactory() {};
        virtual bool RegisterObject(const char* name,
            CreateStorageServiceCallback fn) = 0;
        virtual bool UnregisterObject(const char* name) = 0;
        virtual IService* CreateService(const char* name,
            const char* p_name, const char* p_path, u_long p_id,
            u_long p_parent_id,
            char md5[MD5_DIGEST_SIZE]) = 0;
    protected:
        CallbackMap m_callbacks;
    };

    const char STORAGEOBJECT[] = "storageobject";
    const char STORAGE_FACTORY[] = "storagefactory";

}

#endif	/* ISTORAGE_H */

